package cc.magicjson.p6spy.controller;

import cc.magicjson.p6spy.bo.UserBO;
import cc.magicjson.p6spy.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/users")
@RequiredArgsConstructor
public class UserController {

    private final UserService userService;

    @GetMapping
    public ResponseEntity<List<UserBO>> getAllUsers() {
        return ResponseEntity.ok(userService.getAllUsers());
    }

    @PostMapping
    public ResponseEntity<UserBO> createUser(@RequestBody UserBO userBO) {
        return ResponseEntity.ok(userService.createUser(userBO));
    }

    @GetMapping("/{id}")
    public ResponseEntity<UserBO> getUserById(@PathVariable Long id) {
        return ResponseEntity.ok(userService.getUserById(id));
    }

    @GetMapping("/slow-query")
    public ResponseEntity<Void> simulateSlowQuery() {
        userService.simulateSlowQuery();
        return ResponseEntity.ok().build();
    }
}
